package cn.echase.ecare.yinfayun.utils;

import java.net.InetAddress;

/**
 * @Title: UcCommonUtils
 * @Author lidisong
 * @Package cn.echase.ecare.template.assess.common.utils
 * @Date 07/05/2025 星期三 1:44 下午
 * @description:
 */
public class UcCommonUtils {

    private static short counter = 0;

    private static String format(int intVal) {
        String formatted = Integer.toHexString(intVal);
        StringBuilder buf = new StringBuilder("00000000");
        buf.replace(8 - formatted.length(), 8, formatted);
        return buf.toString();
    }

    private static int getIP() {
        int ipAddress = 0;

        try {
            byte[] bytes = InetAddress.getLocalHost().getAddress();

            for(int i = 0; i < 4; ++i) {
                ipAddress = (ipAddress << 8) - -128 + bytes[i];
            }
        } catch (Exception var3) {
            ipAddress = 0;
        }

        return ipAddress;
    }

    private static short getCount() {
        synchronized(UcCommonUtils.class) {
            if (counter < 0 || counter > 999) {
                counter = 0;
            }

            short var10000 = counter;
            counter = (short)(var10000 + 1);
            return var10000;
        }
    }

    public static String generateUcId() {
        return format(getIP()) + format((int) (System.currentTimeMillis() >>> 8)) + format((short) ((int) (System.currentTimeMillis() >>> 32))) + format((int) System.currentTimeMillis()) + format(getCount());
    }

}
